# 作者: 陈其志 
# 2025年02月18日15时56分30秒 
# 2716847110@qq.com

# # 增删查改不影响id
# student_info = {"name": "小明", 'age': 18}
# print(id(student_info))
# print(student_info['name'])
# print(student_info['age'])
# student_info['gender'] = True
# print(student_info)
# print(id(student_info))
#
# # 删除
# student_info.pop('age')
# print(student_info)
#
# # 统计键值对数量
# print(len(student_info))
#
# # 合并字典
# temp_dict = {'gender': True, 'height': 1.74}
# print(id(student_info))
# student_info.update(temp_dict)  # 键相同覆盖，不同添加
# print(student_info)
# print(id(student_info))
#
# # 默认遍历键
# print('-' * 50)
# for k in student_info:
#     print(k)
# # 遍历键值对，以元组的形式表示
# print('-' * 50)
# for k, v in student_info.items():
#     print(k, v)
# # 遍历值
# print('-' * 50)
# for v in student_info.values():
#     print(v)
#
# card_list = [
#     {"name": "张三",
#      "qq": "12345",
#      "phone": "110"},
#     {"name": "李四",
#      "qq": "54321",
#      "phone": "10086"}
# ]
# for card_info in card_list:
#     print(card_info)  # 字典存放于列表中，遍历读出字典
#
# # 清空字典
# student_info.clear()
# print(student_info)


def use_dict(test_dict):
    """
    字典的增删改查
    :param test_dict:
    :return:
    """
    for k in test_dict:
        print(k)

    for k, v in test_dict.items():
        print(k, v)

    for v in test_dict.values():
        print(v)


def list_dict(list_dict_1):
    for card in list_dict_1:
        print(card)
        for k, v in card.items():
            print(k, v)


if __name__ == '__main__':
    student_info = {"name": "小明", 'age': 18, 'qq': '271684'}
    card_list = [
        {"name": "张三",
         "qq": "12345",
         "phone": "110"},
        {"name": "李四",
         "qq": "54321",
         "phone": "10086"}]
    use_dict(student_info)
    list_dict(card_list)
